/*
 * @Author: szx
 * @Date: 2021-12-27 15:23:34
 * @LastEditTime: 2021-12-27 15:54:01
 * @Description:
 * @FilePath: \leetcode\1-99\77\77.js
 */
var combine = function (n, k) {
    const res = [];
    const backtrack = (arr, index) => {
        if (arr.length == k) {
            res.push(arr.slice());
            return;
        }
        for (let i = index; i <= n - (k - arr.length) + 1; i++) {
            arr.push(i);
            backtrack(arr, i + 1);
            arr.pop();
        }
    };
    backtrack([], 1);
    return res;
};
console.log(combine(9, 3));
